<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    import="java.sql.*"
    import="java.util.Calendar"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>借用服務</title>
<style type="text/css">
<!--
.style3 {
	font-size: 12px;
	font-weight: bold;
	color: #FF0000;
}
-->
</style>
</head>
 
<body>
<% if(session.getAttribute("access") == "y" ){%>
<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<jsp:useBean id="p_state" scope="page" class="bean.StateBean"/>
<jsp:useBean id="pclass" scope="page" class="myclass.P_Class"/>
<table width="750" border="0" align="center">
  <tr>
    <td width="30" rowspan="4"><jsp:include page="../frameset/left.jsp" flush="true" ></jsp:include></td>
    <td colspan="2"><jsp:include page="../frameset/top.jsp" flush="true" ></jsp:include></td>
    <td width="40" rowspan="4"><jsp:include page="../frameset/right.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td rowspan="2"><jsp:include page="../frameset/mean.jsp" flush="true" ></jsp:include>

    </td>
    <td height="32"><jsp:include page="../frameset/borrow_mean.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td>
    <%--內頁--%>
    <%
    String date=""; %>   

<table width="550" border="0" align="center">
  <tr>
    <td width="54%"><jsp:include page="showCal.jsp" flush="true" ></jsp:include></td>
    <td width="18%">觀看日期為</td>
    <td width="28%">
    <%
    Calendar cal =Calendar.getInstance(); 
	String y1 = ""; //查詢開始年份 
   	String m1 = ""; //查詢開始月份 
   	String d1 = ""; //查詢開始日期 
    y1 = String.valueOf(cal.get(cal.YEAR)); 
    m1=String.valueOf(cal.get(cal.MONTH)+1); 
    d1 =String.valueOf(cal.get(cal.DATE));
    date=y1+"/"+m1+"/"+d1; 
    if(request.getParameter("mon")==null){%>
    <span class="style3"><%=date %></span>
    <%
    }
     else{
     	date=request.getParameter("year")+"/"+request.getParameter("mon")+"/"+request.getParameter("day");
    %>
    <span class="style3"><%=date %></span>
    <%
     }%>
    </td>
  </tr>
  <tr align="center">
      <td colspan="3"><br/></td>
  </tr>
  <tr align="right">
      <td colspan="3"><a href="add_memBorrow.jsp" target="_self" class="style2"><img src="images/add_borrow.jpg" / border="0"></a></td>
  </tr>
  <tr align="center">
      <td colspan="3" bgcolor="#FFFF66"><%=date%></td>
  </tr>
  <%
  	String sql="";
  	ResultSet rs;
  	ResultSet rs2;
  	ResultSet rs3;
  	int c_pf=0;
  	sql="select * from BOOK WHERE APPLY_DATE='"+date+"'";
	rs=mydb.executeQuery(sql);
	if(rs.next()){//表示有預借的資料
	
	%>
		<tr>
    	<td colspan="3" >
    		<table width="100%" border="0">
  				<tr>
    				<td>場地/設備編號</td>
    				<td>類別</td>
    				<td>名稱</td>
    				<td>借用者</td>
    				<td>預借時段</td>
    				<td>預借理由</td>
    				<td>允許借用</td>
  				</tr>
  				<%
  				do{ 
  					
  					sql="select * from PLACE WHERE P_ID='"+rs.getString("PF_ID")+"'";
					rs2=mydb.executeQuery(sql);
  					if(rs2.next()){//為場地資料
  						c_pf=1;
  						sql="select * from PLACE_CLASS WHERE PC_ID='"+rs2.getString("P_Class")+"'";
  					}else{
  						sql="select * from FACILITY WHERE F_ID='"+rs.getString("PF_ID")+"'";
						rs2=mydb.executeQuery(sql);
  						if(rs2.next()){//為設備資料
  							c_pf=2;
  							sql="select * from FACILITY_CLASS WHERE FC_ID='"+rs2.getString("F_Class")+"'";
  						}
  					}
          			rs3=pclass.getPcName(sql);
          			rs3.next();
  				%>
  				<tr><form id="form1" name="form1" method="post" action="do_addBorrow.jsp">
    				<td><%=rs.getString("PF_ID")%></td>
    				<td>
    				<%
    				if(c_pf==1){
    					out.print(rs3.getString("PC_NAME"));
    				}else if(c_pf==2){
    					out.print(rs3.getString("FC_NAME"));
    				}
    				 %>
    				</td>
    				<td>
    				<%
    				if(c_pf==1){
    					out.print(rs2.getString("P_NAME"));
    				}else if(c_pf==2){
    					out.print(rs2.getString("F_NAME"));
    				}
    				 %>
    				</td>
    				<td><%=rs.getString("M_ID")%></td>
    				<td><%=rs.getString("BOOK_TIME")%></td>
    				<td><a href="detail_Book.jsp?bn=<%=rs.getString("BOOK_ID")%>&c_pf=<%=c_pf %>" target="_blank" >理由</a></td>
    				<td> <input type="hidden" name="c_pf" value="<%=c_pf%>"><input type="hidden" name="book_id" value="<%=rs.getString("BOOK_ID")%>"><input type="submit" name="Submit" value="允許借用" /></td></form>
  				</tr>
  				<%}while(rs.next()); %>
			</table>
   		</td>
  		</tr>
	<%
	}else{
	%>
  		<tr>
    		<td colspan="3">此天沒有待預借的資料</td>
  		</tr>
	<%
	}
   %>
</table>
    
<%--內頁end--%>
    </td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>
<%
  }
  else{
  	response.sendRedirect("../index.jsp"); //若沒有登入則回到index.jsp
  } 
  %>
</body>
</html>
